const express = require('express');
const utils = require('../../utils/index');
const constant = require('../../utils/constant')
const intervalCopyFileController = require("../../controller/FileSystem/intervalCopyFile");
const svgToPng = require('../../controller/FileSystem/svgToPng');
const multer = require("multer");

const router = express.Router()

// const uploads_path = './' + constant.UPLOADS_PATH
const chunks_path = './' + constant.CHUNKS_PATH

// 配置multer
const uploadStorage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, chunks_path)  //  上传文件保存的路径
    },
    filename: function (req, file, cb) {
        let filename = req.get('filename') || ''
        if (!filename) {
            filename = `doum-workshop ${utils.parseTime(Date.now(), '{y}-{m}-{d} {h}-{i}-{s}')}`
        }
        file.name = filename
        cb(null, filename + '.svg') //  上传文件的名称
    }
})
const svgToPngUpload = multer({ storage: uploadStorage }) //  上传文件的中间件

router.get('/intervalCopyFile/setIntervalCopyFile', intervalCopyFileController.setIntervalCopyFile)

router.get('/intervalCopyFile/clearIntervalCopyFile', intervalCopyFileController.clearIntervalCopyFile)

router.post('/svgToPng', svgToPngUpload.single('file'), svgToPng.svgToPng)

module.exports = router
